import {CLOSE_RECORD_VIDEO, OPEN_RECORD_VIDEO, QUERY,} from '../types/RecordType'
import {queryRecordService} from "../service/Record";

const queryRecordAction = () => {
  return (dispatch) => {
    queryRecordService().then(res => {
      dispatch(queryRecord(res.data));
    }).catch(err => {
      dispatch(
        {
          type: "ERROR",
          payload: {
            err: err
          }
        }
      )
    })
  }
}

const queryRecord = (data) => {
  return {
    type: QUERY,
    payload: data.data.map(it => {
      it.key = it.id;
      return it
    }),
  }
}

const openRecordVideo = (record) => {
  return {
    type: OPEN_RECORD_VIDEO,
    recordVideoVisible: true,
    videoRecord: record
  }
}

const closeRecordVideo = () => {
  return {
    type: CLOSE_RECORD_VIDEO,
    recordVideoVisible: false,
  }
}

export {
  queryRecordAction,
  openRecordVideo,
  closeRecordVideo
}